package com.linzm.v1;

import lombok.SneakyThrows;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * SocketClient
 *
 * @Date: 2023/11/7 22:40
 * @User linziming
 */
public class SocketClient {
    @SneakyThrows
    public static void main(String[] args) {
        start();
    }

    private static void start() throws IOException {
        // 要连接的服务端IP地址和端口
        String host = "127.0.0.1";
        int port = 55533;
        // 与服务端建立连接
        Socket socket = new Socket(host, port);
        // 建立连接后获得输出流
        OutputStream outputStream = socket.getOutputStream();
        String message = "你好  ";
        socket.getOutputStream().write(message.getBytes(StandardCharsets.UTF_8));
        outputStream.close();
        socket.close();
    }
}
